package logic

import (
	"context"

	"tianji-network/service/satellite/rpc/internal/svc"
	"tianji-network/service/satellite/rpc/model"
	"tianji-network/service/satellite/rpc/satellite"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetAllLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetAllLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAllLogic {
	return &GetAllLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetAllLogic) GetAll(in *satellite.Empty) (*satellite.SatellitelListResp, error) {
	satelliteModelList, err := l.svcCtx.Model.FindAll(l.ctx)
	if err != nil {
		return nil, err
	}
	satellitelList := make([]*satellite.SatelliteOne, 0)
	for _, s := range *satelliteModelList {
		satelliteOne := model.ModelConvertToProto(&s)
		satellitelList = append(satellitelList, satelliteOne)
	}

	return &satellite.SatellitelListResp{
		SatelliteList: satellitelList,
	}, nil
}
